package cc.linker.steplink.crm.merchanth5.controller.acs;

import cc.linker.steplink.crm.commons.domain.WxUser;
import cc.linker.steplink.crm.merchanth5.commons.RequestFilter;
import cc.linker.steplink.crm.merchanth5.service.acs.PromoterClueService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 加盟代理线索
 */
@Slf4j
@RestController
@RequestMapping("/acs/promoterClue")
public class PromoterClueCotroller {

    @Autowired
    private PromoterClueService promoterClueService;
    @Autowired
    private RequestFilter requestFilter;

    /**
     * 获取销售线索列表
     *
     * @param request
     * @param pageIndex
     * @param pageSize
     * @param type : 线索类型
     * @return
     */
    @GetMapping("/getList")
    public PageInfo getList(HttpServletRequest request,Integer type,
                                          @RequestParam(value = "pageIndex", defaultValue = "1", required = false) int pageIndex,
                                          @RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        WxUser wxUser = requestFilter.getWxUser(request);
        String promoterId = wxUser.getCustomerId();
        return new PageInfo<>(promoterClueService.getList(promoterId,type));
    }

    /**
     * 获取客户详情销售线索列表
     *
     * @param request
     * @param pageIndex
     * @param pageSize
     * @param customerId ： 客户id
     * @param type : 线索类型
     * @return
     */
    @GetMapping("/getCustomerClueList")
    public PageInfo getCustomerClueList(HttpServletRequest request,String customerId,Integer type,
                                          @RequestParam(value = "pageIndex", defaultValue = "1", required = false) int pageIndex,
                                          @RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        WxUser wxUser = requestFilter.getWxUser(request);
        String promoterId = wxUser.getCustomerId();
        return new PageInfo<>(promoterClueService.getCustomerClueList(promoterId,customerId,type));
    }

    /**
     * 获取客户详情
     *
     * @param request
     * @param customerId ： 客户id
     * @return
     */
    @GetMapping("/getCustomerInfo")
    public Map getCustomerList(HttpServletRequest request, String customerId) {
        WxUser wxUser = requestFilter.getWxUser(request);
        String promoterId = wxUser.getCustomerId();
        return promoterClueService.getCustomerInfo(promoterId,customerId);
    }

    /**
     * 添加记录
     *
     * @param request
     * @param params ：参数
     * @return
     */
    @PostMapping("/addClue")
    public void addClue(@RequestBody Map<String, Object> params,HttpServletRequest request) {
        WxUser wxUser = requestFilter.getWxUser(request);
        params.put("customerId",wxUser.getCustomerId());
        params.put("nickName",wxUser.getNickname());
        params.put("orgId",wxUser.getOrgId());
        promoterClueService.addClue(params);
    }
}
